/*
 * @Author: Shiire
 * @Date: 2022-02-17 15:31:39
 * @LastEditors: Shiire
 * @LastEditTime: 2022-08-21 15:52:54
 * @Description: 
 * @FilePath: \grapro\vue.config.js
 */


const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin
const CompressionWebpackPlugin = require('compression-webpack-plugin');

module.exports = {
    // 关闭 eslint
    lintOnSave: false,

    configureWebpack: config => {
        // gzip压缩
        config.plugins.push(
            new CompressionWebpackPlugin(
                {
                    filename: info => {
                        return `${info.path}.gz${info.query}`
                    },
                    algorithm: 'gzip',
                    threshold: 10240, // 只有大小大于该值的资源会被处理 10240
                    test: /\.js$|\.html$|\.css/,
                    minRatio: 0.8, // 只有压缩率小于这个值的资源才会被处理
                    // deleteOriginalAssets: false // 删除原文件
                }
            )
        )
    },

    chainWebpack: config => {
        // 移除 preload(预载) 插件
        config.plugins.delete('preload')
        // 移除 prefetch(预取) 插件
        config.plugins.delete('prefetch')
        // 展示图形化信息
        config
            .plugin('webpack-bundle-analyzer')
            .use(BundleAnalyzerPlugin)

        // 图片按需加载
        // config.module.rule('images')
        //     .test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
        //     .use('image-webpack-loader')
        //     .loader('image-webpack-loader')
        //     .options({
        //         bypassOnDebug: true
        //     })
        //     .end()
    },

    devServer: {
        proxy: {
            '/api': {
                target: 'http://127.0.0.1:3000',
                ws: true,   // websocket
                changeOrigin: true,   // 控制请求头中的HOST值
                pathRewrite: {
                    '^/api': ''
                }
            }
        }
    }
}